home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-09 | 6.8 KB | 209 lines | [TEXT/CWIE] |
- //
- // LTimeDateControl v1.0
- // A time and date picker for Power Plant.
- //
- // Copyright © 1995 by Michael F. Kamprath
- // mailto:kamprath@kagi.com
- // http://www.leonardo.net/kamprath/claireware.html
- //
- // Abstract
- // --------
- //
- // LTimeDateControl is a drop in module to give your Power Plant based application an
- // easy to use, graphical time and/or date picker. The user interface of LTimeDateControl
- // allows a user to click on a portion of a date and/or time string, and then change it's
- // value by clicking on an arrow or with the arrow keys.
- //
- // ConOps
- // ------
- //
- // To use, add a LControl pane to a view in your application and make it's class ID 'TmDt'.
- // Fill out it's values as you would a normal LControl with the following exceptions:
- //
- // 1. Min, Max, and Initial vlaue of the LControl is ignored. LTimeDateControl does
- // not use LControl's value tracking mechanism.
- //
- // 2. The user constant must be set to the variation of the LTimeDateControl you wish
- // to use. Variation IDs are:
- //
- // Type | ID
- // ===========================
- // Time only | 1
- // Long Date only | 2
- // Long Date & Time | 3
- // Short Date only | 4 (not supported yet in v1.0)
- // Short Date & Time | 5 (not supported yet in v1.0)
- //
- // 3. You may set a text traits ID for LTimeDateControl, but you must ensure the
- // frame you define for LTimeDateControl is at least the font's height plu 5 pixels
- // and an appropiate width to contain the date/time string plus 20 pixels in
- // width. Some expirementation will probably be needed to get the look you want.
- //
- // LTimeDateControl ignores LControl's value tracking mechanism in favor of it's
- // own. You may track a LTimeDateControl's value in either seconds (unsigned long)
- // or by a DateTimeRec. You may get the current value of LTimeDateControl with:
- //
- // Uint32 LTimeDateControl::GetDateTimeValue( void )
- // DateTimeRec LTimeDateControl::GetDateTimeRec( void )
- //
- // And set the current value with:
- //
- // void LTimeDateControl::SetDateTimeValue( const Uint32& inValue )
- // void LTimeDateControl::SetDateTimeValue( const DateTimeRec& inRec )
- //
- // When ever the user changes a LTimeDateControl value (note, not when it is
- // programatically changed), LTimeDateControl broadcasts a msg_TimeDateHasChanged
- // message (defined in LTimeDateControl.h) to any LListener's attached to the
- // LTimeDateControl. In the ioParameter of the message, the LTimeDateControl's pane
- // ID is passed.
- //
- // LTimeDateControl inherits off of LCommander (along with LControl) so that it will
- // de-hilite the currently selected date portion when it is no longer "in focus" and
- // to get keyDown messages.
- //
- // LTimeDateControl utilizes a StOffscreenGWorld so that a "smooth" redraw will be done.
- // Be sure to include the PowerPlant file "UGWorld.cp" in your project. LTimeDateControl
- // honors it's parent view's background color where appropiate (ensure that a call to
- // ApplyForeAndBackColors() will properly set it at the time of LTimeDateControl redraw).
- //
- // Be sure to also include the file LTimeDateControl.rsrc in your project. It contains
- // the control's arrow icons. Of course, you can change them to maintain your "look and feel"
- //
- // Legalisms
- // ---------
- //
- // You may freely use LTimeDateControl with the following exceptions:
- //
- // 1. If you use LTimeDateControl in your project, e-mail me so that I can keep you
- // posted when I release new versions.
- // 2. If you use LTimeDateControl in a project that you release to the public and
- // charge money for, I ask for a free & registered version of the product.
- // 3. No derivatives of LTimeDateControl may be publicly release with out my consent.
- //
-
- #ifndef __LTIMEDATECONTROL__
- #define __LTIMEDATECONTROL__
-
- #include <LControl.h>
- #include <LCommander.h>
-
- class LTimeDateControl : public LControl,
- public LCommander
- {
- public:
- // public enums
-
- typedef enum
- {
- kTimeVariation = 1,
- kLongDateVariation = 2,
- kLongDateAndTimeVariation = 3,
- kShortDateVariation = 4,
- kShortDateAndTimeVariation = 5
- } ETimeDateControlType;
-
- enum
- {
- kNoPart = 0x0000,
-
- kArrowPartMask = 0x00FF,
- kInUpArrow = 0x0002,
- kInDownArrow = 0x0004,
-
- kTextComponentMask = 0xFF00,
- kDateHiliteMask = 0x0F00,
- kTimeHiliteMask = 0XF000,
-
- kMonthItem = 0x0100,
- kDateItem = 0x0200,
- kYearItem = 0x0300,
- kDayOfWeekItem = 0x0400,
- kHourItem = 0x1000,
- kMinuteItem = 0x2000,
- kSecondItem = 0x3000,
- kAMPMItem = 0x4000
-
- };
-
- enum { class_ID = 'TmDt' };
-
- // the functions
-
- static LTimeDateControl* CreateTimeDateControlStream( LStream *inStream);
-
- LTimeDateControl();
- LTimeDateControl( const LTimeDateControl &inOriginal);
- LTimeDateControl( const SPaneInfo &inPaneInfo,
- MessageT inValueMessage,
- Uint32 inValue,
- ETimeDateControlType inVariation );
- LTimeDateControl( LStream *inStream);
- virtual ~LTimeDateControl();
-
- // Custom Value Trackking
-
- Uint32 GetDateTimeValue( void ) const;
- void SetDateTimeValue( const Uint32& inValue );
- DateTimeRec GetDateTimeRec( void ) const;
- void SetDateTimeValue( const DateTimeRec& inRec );
-
- // Power Plant Support
-
- virtual Boolean FocusDraw();
- virtual void DrawSelf();
-
- virtual void ClickSelf(const SMouseDownEvent &inMouseDown);
-
- virtual Boolean HandleKeyPress( const EventRecord &inKeyEvent);
-
- protected:
- virtual void ActivateSelf();
- virtual void DeactivateSelf();
-
- virtual void BeTarget();
- virtual void DontBeTarget();
-
- virtual Int16 FindHotSpot(Point inPoint);
- virtual void HotSpotAction(Int16 inHotSpot, Boolean inCurrInside, Boolean inPrevInside);
- virtual void HotSpotResult(Int16 inHotSpot);
-
- private:
- void InitDateTimeControl( void );
- void InitDateStarts( void );
-
- void DrawDateTimeControl( const Uint16& theHotSpot = 0 );
-
- Int16 DrawTimeString( const Point& startPos,
- const Rect& strRect,
- const Uint16& hilite );
- Int16 DrawLongDateString( const Point& startPos,
- const Rect& strRect,
- const Uint16& hilite );
-
-
- Uint16 TestTimeString( const Rect& strRect, const Point& hitPt, Int16& width );
- Uint16 TestLongDateString( const Rect& strRect, const Point& hitPt, Int16& width );
-
- void ArrowAction( Uint16 inHotSpot, Boolean holdClick );
-
- ETimeDateControlType mVariation;
- Uint32 mDateTimeValue;
- Uint32 mLastClickTickCount;
- Intl0Hndl mTimeFormatH;
- Intl1Hndl mDateFormatH;
- Uint16 mCurrentHilite;
- ResIDT mCntlTextTraitsID;
- Int16 mStartArray[4],
- mEndArray[4]; /* Array posistions
- *
- * 0 - date num - Hour
- * 1 - Day Name - Minute
- * 2 - Month - AM/PM
- * 3 - year
- */
- };
-
- const MessageT msg_TimeDateHasChanged = 10002; // send this panelID as param
-
- #endif
-